module Proxy.Commands where
import Proxy.Game
import Proxy.Messages
import Proxy.UnitTypes
import Proxy.TechTypes
import Proxy.UpgradeTypes
import qualified Proxy.CommandTypes as CT

s = (';':)
args1 a = serializes a ";0;0;0"
args2 a b = serializes a . s $ serializes b ";0;0" 
args3 a b c = serializes a . s . serializes b . s $ serializes c ";0"
args4 a b c d = serializes a . s . serializes b . s . serializes c . s $ serializes d ""

---------------------------------------------------------------
-- Command Signatures
---------------------------------------------------------------

atLocation                                          :: CT.CommandType -> UnitId -> Location -> Command
atLocation ct unitId (x, y)                         = Command ct $ args3 unitId x y

atUnit                                              :: CT.CommandType -> UnitId -> UnitId -> Command
atUnit ct unitId                                    = Command ct . args2 unitId

withTechTypeAtUnit                                  :: CT.CommandType -> UnitId -> TechType -> UnitId -> Command
withTechTypeAtUnit ct unitId techType               = Command ct . args3 unitId techType

atUnitType                                          :: CT.CommandType -> UnitId -> UnitType -> Command
atUnitType ct unitId                                = Command ct . args2 unitId

atLocationWithUnitType                              :: CT.CommandType -> UnitId -> Location -> UnitType -> Command
atLocationWithUnitType ct unitId (x, y)             = Command ct . args4 unitId x y

withTechTypeAtLocation                              :: CT.CommandType -> UnitId -> TechType -> Location -> Command
withTechTypeAtLocation ct unitId techType (x, y)    = Command ct $ args4 unitId techType x y

atTechType                                          :: CT.CommandType -> UnitId -> TechType -> Command
atTechType ct unitId                                = Command ct . args2 unitId

atUpgradeType                                       :: CT.CommandType -> UnitId -> UpgradeType -> Command
atUpgradeType ct unitId                             = Command ct . args2 unitId

atNothing                                           :: CT.CommandType -> UnitId -> Command
atNothing ct                                        = Command ct . args1

atSlot                                              :: CT.CommandType -> UnitId -> Slot -> Command
atSlot ct unitId                                    = Command ct . args2 unitId

setValue                                            :: CT.CommandType -> Int -> Command
setValue ct                                         = Command ct . args1

---------------------------------------------------------------
-- Commands
---------------------------------------------------------------

attackMove          = atLocation CT.AttackMove
rightClickAt        = atLocation CT.RightClickAt
patrol              = atLocation CT.Patrol
setRallyPosition    = atLocation CT.SetRallyPosition
land                = atLocation CT.Land
unloadAllAt         = atLocation CT.UnloadAllAt

attackUnit          = atUnit CT.AttackUnit
rightClickOn        = atUnit CT.RightClickOn
follow              = atUnit CT.Follow
setRallyUnit        = atUnit CT.SetRallyUnit
repair              = atUnit CT.Repair
load                = atUnit CT.Load
unload              = atUnit CT.Unload

useTechOn           = withTechTypeAtUnit CT.UseTechOn

train               = atUnitType CT.Train
buildAddon          = atUnitType CT.BuildAddon
morph               = atUnitType CT.Morph

build               = atLocationWithUnitType CT.Build

useTechAt           = withTechTypeAtLocation CT.UseTechAt

research            = atTechType CT.Research
useTech             = atTechType CT.UseTech

upgrade             = atUpgradeType CT.Upgrade

stop                = atNothing CT.Stop
holdPosition        = atNothing CT.HoldPosition
burrow              = atNothing CT.Burrow
unburrow            = atNothing CT.Unburrow
seige               = atNothing CT.Seige
unseige             = atNothing CT.Unseige
cloak               = atNothing CT.Cloak
decloak             = atNothing CT.Decloak
lift                = atNothing CT.Lift
unloadAll           = atNothing CT.UnloadAll
cancelConstruction  = atNothing CT.CancelConstruction
haltConstruction    = atNothing CT.HaltConstruction
cancelMorph         = atNothing CT.CancelMorph
cancelTrain         = atNothing CT.CancelTrain
cancelAddon         = atNothing CT.CancelAddon
cancelResearch      = atNothing CT.CancelResearch
cancelUpgrade       = atNothing CT.CancelUpgrade

cancelTrainOn       = atSlot CT.CancelTrainOn

setGameSpeed        = setValue CT.SetGameSpeed
